import { GSprite } from "../../../../../com/mui/controls/GSprite";
import { IToolTipItem } from "../../../../../com/mui/manager/IToolTipItem";
import { ToolTipsManager } from "../../../../../com/mui/manager/ToolTipsManager";
import { EqStrengthEnableBtn } from "../../player/equip/EqStrengthEnableBtn";
import { ObjCreate } from "../../common/ObjCreate";
import { GTextFormat } from "../../../../common/GTextFormat";
import { FontUtil } from "../../../../common/font/FontUtil";
import { PetUtil } from "../info/PetUtil";
import { StrengthAddConfig } from "../../../resource/StrengthAddConfig";
import { EquipTargetType } from "../../../resource/info/EquipTargetType";
import { StrengthenAddInfo } from "../../../resource/info/StrengthenAddInfo";
import { PetEquipUtil } from "../../common/util/PetEquipUtil";
import { ToolTipInfo } from "../../../model/ToolTipInfo";
import { NormalTooltip } from "../../common/tooltip/NormalTooltip";
import { ColorConfig } from "../../../resource/ColorConfig";
import { EColor } from "../../../../../Message/Public/EColor";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { Language } from "../../../../../extend/language/Language";
import { GTextFiled } from "../../../../../com/mui/controls/GTextFiled";
type int = number;
//class PetEquipJewelTargetAddPanel
    
    export  class PetEquipJewelTargetAddPanel extends GSprite implements IToolTipItem
    {
        constructor()
        {
            super();
            this._equips = [];
            this.initUI();
            ToolTipsManager.register(this);
            return;
        }

        protected initUI(): void
        {
            this._jewelBtn = new EqStrengthEnableBtn();
            this._jewelBtn.label = "";
            this._jewelBtn.setSize(33, 28);
            this._jewelBtn.x = 0;
            this._jewelBtn.y = 0;
            this._jewelBtn.styleName = "EquipJewelAddDisableBtn";
            addChild(this._jewelBtn);
            this._ganTxt = ObjCreate.createTextField("Lv.", this._jewelBtn.x + 2, this._jewelBtn.y + 25, 40, 20, this, new GTextFormat(FontUtil.songtiName, 12, 16776960));
            this._ganTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._jewelTxt = ObjCreate.createTextField("0", this._ganTxt.x + 18, this._jewelBtn.y + 26, 40, 20, this, new GTextFormat(FontUtil.EmbedNumberName, 14, 16776960));
            this._jewelTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._jewelTxt.embedFonts = true;
            return;
        }

        public updateJewelAddInfo(arg1: int, arg2: Array<any>): void
        {
            var loc3=null;
            this._career = PetUtil.getCareer(arg1);
            this._equips = arg2;
            this._isEnabled = false;
            var loc1=false;
            var loc2=StrengthAddConfig.instance.getAddInfoArray(EquipTargetType.PetEquipJewelTarget, this._career);
            var loc4=new Map<any, any> /* flash.utils.Dictionary */();
            var loc5=0;
            while (loc5 < loc2.length) 
            {
                loc3 = loc2[loc5] as StrengthenAddInfo;
                if (loc4[loc3.level] == null) 
                {
                    this._jewelAmount = PetEquipUtil.getJewelAmountByLevel(arg2, loc3.level);
                    loc4[loc3.level] = this._jewelAmount;
                }
                else 
                {
                    this._jewelAmount = loc4[loc3.level];
                }
                loc1 = this._jewelAmount >= loc3.amount;
                if (loc1) 
                {
                    this._jewelBtn.styleName = "EquipJewelAddEnableBtn";
                    this._jewelTxt.text = "" + loc3.level;
                    this._addInfo = loc3;
                    this._isEnabled = true;
                }
                else if (loc5 != 0) 
                {
                    break;
                }
                else 
                {
                    this._jewelBtn.styleName = "EquipJewelAddDisableBtn";
                    this._jewelTxt.text = "" + loc3.level;
                    this._addInfo = loc3;
                    break;
                }
                ++loc5;
            }
            this._jewelBtn.drawNow();
            this.updateTooltipData();
            return;
        }

        /* internal  */updateTooltipData(): void
        {
            var loc1=null;
            var loc2=null;
            var loc6=null;
            var loc7=0;
            var loc8=null;
            var loc9=0;
            var loc10=0;
            var loc11=0;
            var loc12=0;
            var loc13=null;
            if (!this._addInfo) 
            {
                this._toolTipData = null;
                return;
            }
            if (!this._toolTipData) 
            {
                this._toolTipData = new ToolTipInfo(NormalTooltip.ToolTipRenderType_Separate, []);
            }
            if (this._addInfo.level <= 7) 
            {
                loc2 = ColorConfig.instance.getItemColorString(EColor._EColorBlue);
            }
            else 
            {
                loc2 = ColorConfig.instance.getItemColorString(EColor._EColorPurple);
            }
            var loc3=[];
            var loc4="";
            if (this._isEnabled) 
            {
                loc4 = (loc4 = loc4 + HTMLUtil.addColor("<font size=\'14\'>" + Language.getStringByParam(61087, this._addInfo.amount, this._addInfo.level) + "</font>\n", loc2)) + HTMLUtil.addColor(Language.getString(30035) + "\n\n", "#00ff00");
                loc1 = "#f0ea3f";
            }
            else 
            {
                loc4 = (loc4 = loc4 + HTMLUtil.addColor("<font size=\'14\'>" + Language.getStringByParam(61071, this._addInfo.amount, this._addInfo.level, this._jewelAmount, this._addInfo.amount) + "</font>\n", loc2)) + HTMLUtil.addColor(Language.getString(30036) + "\n\n", "#ff0000");
                loc1 = "#7c7c7c";
            }
            var loc5=this.getAttributeString(this._addInfo);
            loc4 = loc4 + ("<textFormat leading=\'3\'>" + HTMLUtil.addColor(loc5, loc1) + "<textFormat>\n");
            loc3.push(loc4);
            loc4 = "";
            if (this._isEnabled) 
            {
                if (!((loc7 = (loc6 = StrengthAddConfig.instance.getAddInfoArray(EquipTargetType.PetEquipJewelTarget, this._career)).indexOf(this._addInfo)) == -1) && loc7 + 1 < loc6.length) 
                {
                    if ((loc8 = loc6[loc7 + 1] as StrengthenAddInfo) && loc8.level <= this._hightLevel) 
                    {
                        if (this._addInfo.level != this._lowLevel) 
                        {
                            if (this._addInfo.level > this._lowLevel) 
                            {
                                loc11 = (loc8.level - 1);
                                loc9 = PetEquipUtil.getJewelAmountByLevel(this._equips, loc11);
                                loc10 = this._hightAmount;
                            }
                        }
                        else 
                        {
                            loc11 = this._addInfo.level;
                            loc9 = PetEquipUtil.getJewelAmountByLevel(this._equips, loc11);
                            loc10 = this._addInfo.amount;
                        }
                        loc2 = loc9 >= loc10 ? "#60e71e" : "#FF0000";
                        loc4 = (loc4 = (loc4 = loc4 + HTMLUtil.addColor(Language.getString(61088) + "\n", "#B1efff")) + HTMLUtil.addColor(Language.getStringByParam(61071, loc10, loc11, loc9, loc10, loc2) + "\n", "#7c7c7c")) + HTMLUtil.addColor(Language.getString(61089) + "\n", "#B1efff");
                        loc12 = PetEquipUtil.getJewelAmountByLevel(this._equips, loc8.level);
                        loc13 = this.getAttributeString(loc8);
                        loc2 = loc12 >= loc8.amount ? "#60e71e" : "#FF0000";
                        loc4 = (loc4 = loc4 + HTMLUtil.addColor(Language.getStringByParam(61072, loc8.amount, loc8.level, loc12, loc8.amount, loc2) + "\n", "#7c7c7c")) + ("<textFormat leading=\'3\'>" + HTMLUtil.addColor(loc13, "#7c7c7c") + "<textFormat>\n");
                        loc3.push(loc4);
                    }
                }
                else if (loc7 + 1 >= loc6.length) 
                {
                    loc4 = HTMLUtil.addColor(Language.getString(60374), "#7c7c7c");
                    loc3.push(loc4);
                }
            }
            else 
            {
                loc4 = HTMLUtil.addColor(Language.getStringByParam(61073, this._addInfo.amount, this._addInfo.level), "#7c7c7c");
                loc3.push(loc4);
            }
            this._toolTipData.tooltipData = loc3;
            return;
        }

        /* internal  */getAttributeString(arg1: StrengthenAddInfo): string
        {
            var loc2=null;
            var loc3=null;
            var loc4=null;
            var loc1="";
            var loc5=StrengthAddConfig.instance.getAttributeInfo(arg1);
            var loc6=0;
            while (loc6 < loc5.length) 
            {
                loc2 = loc5[loc6];
                loc3 = loc2["name"] as string;
                loc4 = loc2["value"] as string;
                if (loc3.length != 2) 
                {
                    loc1 = loc1 + ("  " + loc3 + "    " + loc4 + "\n");
                }
                else 
                {
                    loc1 = loc1 + ("  " + loc3 + "            " + loc4 + "\n");
                }
                ++loc6;
            }
            return loc1;
        }

        public get toolTipData()
        {
            return this._toolTipData;
        }

        public set toolTipData(arg1)
        {
            this._toolTipData = arg1;
            return;
        }

        /* internal */ /* var */_jewelBtn: EqStrengthEnableBtn;

        /* internal */ /* var */_jewelTxt: GTextFiled;

        /* internal */ /* var */_ganTxt: GTextFiled;

        /* internal */ /* var */_addInfo: StrengthenAddInfo;

        /* internal */ /* var */_isEnabled: Boolean=false;

        /* internal */ /* var */_career: int=0;

        /* internal */ /* var */_equips: Array<any>;

        /* internal */ /* var */_jewelAmount: int=0;

        /* internal */ /* var */_lowLevel: int=4;

        /* internal */ /* var */_hightLevel: int=8;

        /* internal */ /* var */_lowAmount: int=5;

        /* internal */ /* var */_hightAmount: int=15;

        /* internal */ /* var */_toolTipData: ToolTipInfo;
    }
